import {Hardware} from './Hardware'
const ws = require('nodejs-websocket');

var first = require('rxjs/operators/first').first;
var filter = require('rxjs/operators/filter').filter;
var delay = require('rxjs/operators/delay').delay;

class VueClient extends Hardware {

    /* 生成说明文档 */
    generateDocument() {
        return `
     

        `
    }
    constructor(uid, config) {
        super(uid, config)

        this.server = null
        this.conn = null
    }

    /* 重启所有进程  */
    restartAllSoftware() {
        let cp = this.child_process
        cp.exec("sudo supervisorctl reload", function (err, stdout, stderr) {
            if (err) {
                console.error(err);
            }
            console.log("stdout:", stdout)
            console.log("stderr:", stderr);
        });
    }

    shutdown() {
        let child_process = require("child_process");
        child_process.exec("shutdown now", function (err, stdout, stderr) {
            if (err) {
                console.error(err);
            }
            console.log("stdout:", stdout)
            console.log("stderr:", stderr);
        });
    }


    /* 配置使用sudo命令不用输入密码 */
    sudoWithoutPassword() {

    }

    mounted() {
        let that = this
        this._prepareSubject() //准备好主题
        this._connectToServer()
        this._bindListener()

        
        setTimeout(() => {
            that.dataRoot.$(that.dataRoot, 'onSocketText').valueChangeSubject
            .pipe(filter(param => param.newValue.path == "/handData")) 
            .subscribe(function (param) {
                
                let msg = param.newValue
                console.log(msg)
                
            })   
        }, 1000);
    }

}

export {VueClient}